package cc.rengu.igas.opms.core.service.trans.gateway;

import cc.rengu.igas.acct.facade.bean.MchtAdjustDetail;
import cc.rengu.igas.acct.facade.request.VirtAcctMultiMchntAdjustRequest;
import cc.rengu.igas.momp.facade.base.Header;
import cc.rengu.igas.momp.facade.bean.ClaimCouponMcInfoBean;
import cc.rengu.igas.momp.facade.request.ClaimCouponRequest;
import cc.rengu.igas.momp.facade.request.ComboPaymentReversalRequest;
import cc.rengu.igas.opms.common.constant.OpmsParamConstant;
import cc.rengu.igas.opms.common.constant.OpmsServiceConstant;
import cc.rengu.igas.opms.common.enums.FeeTypeEnum;
import cc.rengu.igas.opms.common.enums.RespCodeEnum;
import cc.rengu.igas.opms.facade.request.UpgwResultNoticeRequest;
import cc.rengu.igas.opms.facade.response.UpgwResultNoticeResponse;
import cc.rengu.igas.share.common.constant.ShareParamConstant;
import cc.rengu.igas.share.common.enums.SettleAcctTypeEnum;
import cc.rengu.igas.share.common.util.GlobalEsbUtil;
import cc.rengu.igas.share.core.model.MchntAcctInfo;
import cc.rengu.igas.share.core.model.MchntInfo;
import cc.rengu.igas.share.core.model.UserInfo;
import cc.rengu.igas.share.core.realize.CsmcService;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.UserService;
import cc.rengu.igas.share.core.realize.impl.CsmcServiceImpl;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.igas.share.core.realize.impl.UserServiceImpl;
import cc.rengu.oltp.service.base.BizBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.MchntOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.ChannelCallCfg;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.OrderInfo;
import cc.rengu.oltp.service.model.RiskMonitorInfo;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.TransCustomImpl;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.utility.util.*;
import com.alibaba.fastjson.JSON;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 银联新网银交易结果通知处理服务类
 */
public class UpgwResultNoticeService extends BizBaseService implements TransCustomImpl {

    @Override
    protected Object beforeBizProcess() throws Exception {
        UpgwResultNoticeRequest upgwResultNoticeRequest = new UpgwResultNoticeRequest();
        ConvertUtil.convertOutput(upgwResultNoticeRequest);
        return upgwResultNoticeRequest;
    }

    @Override
    protected BizResponse callBizService(Object request) throws Exception {

        //贷记终态通知交易类型
        final String CREDIT_REFORM_TRX_TP = "3004";

        UpgwResultNoticeRequest upgwResultNoticeRequest = (UpgwResultNoticeRequest) request;
        rglog.debug("接受到新网银通知报文，开始处理网银通知报文:<{}>", JSON.toJSONString(upgwResultNoticeRequest));
        rglog.info("新网银交易通知中原订单号:<{}>,原系统流水号:<{}>", upgwResultNoticeRequest.getOriOrdrId(), upgwResultNoticeRequest.getOriTrxId());

        /*
         * 根据通知交易的交易类型判断当前通知是贷记终态通知还是网关支付的通知
         * 贷记终态通知与网关支付通知采取不同的处理方法
         */
        if (CREDIT_REFORM_TRX_TP.equals(upgwResultNoticeRequest.getReformTrxTp())) {

            //贷记终态通知 SW-IS
            rglog.info("接受到贷记终态通知，开始处理原退款交易");
            dealCreditTransFinalStateNotice(upgwResultNoticeRequest);
        } else {

            rglog.info("接受到正交易:<{}>交易通知，原支付交易的交易类型:<{}>", upgwResultNoticeRequest.getReformTrxTp(), upgwResultNoticeRequest.getOriTrxTp());
            //根据通知的交易类型区分是 交易状态通知/交易结果通知/交易终态通知
            switch (upgwResultNoticeRequest.getReformTrxTp()) {
                //交易状态通知 SW-AC
                case "3015":
                    dealTransStatusNotice(upgwResultNoticeRequest);
                    break;
                //交易结果通知 SW-AC
                case "3016":
                    dealTransResultNotice(upgwResultNoticeRequest);
                    break;
                //交易终态通知 SW-AC
                case "3012":
                    dealTransFinalStateNotice(upgwResultNoticeRequest);
                    break;
                default:
                    rglog.info("不识别的通知交易类型:<{}>", upgwResultNoticeRequest.getReformTrxTp());
            }
        }

        //响应信息，不管交易结果如何都返回交易成功
        BizResponse<UpgwResultNoticeResponse> bizResponse = new BizResponse<>();
        UpgwResultNoticeResponse upgwResultNoticeResponse = new UpgwResultNoticeResponse();
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(upgwResultNoticeResponse);
        return bizResponse;
    }

    @Override
    protected void afterBizProcess(BizResponse response) throws Exception {
        BizResponse<UpgwResultNoticeResponse> bizResponse = new BizResponse<>();
        UpgwResultNoticeResponse upgwResultNoticeResponse = bizResponse.getResult();
        ConvertUtil.convertInput(upgwResultNoticeResponse);
    }

    @Override
    protected RiskMonitorInfo getRiskMonitorInfo() {
        return null;
    }

    /**
     * 贷记终态通知
     * 作为发卡方在超时时间结束后未给银联返回退款的应答报文，银联会发起贷记终态通知报文。退款的交易状态以银联的通知为准
     *
     * @param upgwResultNoticeRequest 通知报文
     */
    private void dealCreditTransFinalStateNotice(UpgwResultNoticeRequest upgwResultNoticeRequest) {

        rglog.info("发卡侧接受的贷记终态通知，当前不支持处理这种交易");
    }

    /**
     * 交易状态通知
     * 企业网关支付需要付款方复合时通过当前交易告知交易状态
     * 收到当前通知时交易状态非终态，交易状态更新为支付中-03
     *
     * @param upgwResultNoticeRequest 通知报文
     */
    private void dealTransStatusNotice(UpgwResultNoticeRequest upgwResultNoticeRequest) throws Exception {

        rglog.info("收到交易状态通知，更新订单业务状态为支付中....");
        //获取支付订单信息 支付订单不存在则不处理该笔订单
        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
        List<PayOrderInfo> payOrderInfos = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == payOrderInfos || payOrderInfos.isEmpty()) {
            rglog.info("支付订单不存在，当前订单未发起支付");
            return;
        }
        Optional<PayOrderInfo> esbPayOrderInfo = payOrderInfos.stream().filter(payOrderInfo -> ChannelEnum.ESB.getChannelType().equals(payOrderInfo.getMsgDstId())
                && ChannelEnum.UPGW.getChannelType().equals(payOrderInfo.getDstChannelType())).findFirst();
        if (!esbPayOrderInfo.isPresent()) {
            rglog.info("当前订单并没有发起网银网关支付，后续不处理");
            return;
        }

        //判断订单是否已经完成,若订单状态明确则不更新订单状态
        rglog.debug("判断订单是否已经完成....");
        PayOrderInfo payOrderInfo = esbPayOrderInfo.get();
        if (TransStatusEnum.TRANS_SUCC.getStatus().equals(payOrderInfo.getTransStatus()) &&
                (BizStatusEnum.FINISH.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.PART_REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.CONFIRM.getStatus().equals(payOrderInfo.getBizStatus()))) {
            rglog.info("订单已完成，不处理直接返回结果。payOrderTransStatus:<{}>,payOrderBizStatus:<{}>", payOrderInfo.getTransStatus(), payOrderInfo.getBizStatus());
            return;
        }

        //根据原订单号查询用户订单，商户订单
        rglog.debug("流程日志-获取用户订单....");
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == userOrderInfo) {
            rglog.info("用户订单不存在,交易状态通知数据错误。交易终止");
            return;
        }

        //获取商户订单 若商户订单不存在，则直接更新用户订单交易状态为失败
        rglog.debug("流程日志-获取商户订单....");
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        List<MchntOrderInfo> mchntOrderInfos = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == mchntOrderInfos || mchntOrderInfos.isEmpty()) {

            rglog.info("商户订单不存在，instId:<{}>,sysSeqNum:<{}>", upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
            return;
        }

        //更新用户订单/商户订单/支付订单的业务状态为支付中
        rglog.debug("流程日志-更新订单业务状态为支付中-03...");
        userOrderInfo.setBizStatus(BizStatusEnum.PAYING.getStatus());
        mchntOrderInfos.stream().forEach(mchntOrderInfo -> mchntOrderInfo.setBizStatus(BizStatusEnum.PAYING.getStatus()));
        esbPayOrderInfo.get().setBizStatus(BizStatusEnum.PAYING.getStatus());
        OrderService orderService = new OrderServiceImpl();
        if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfos, esbPayOrderInfo.get())) {
            rglog.error("更新订单信息失败....");
        }
    }

    /**
     * 交易结果通知
     * 个人网关/企业网关支付等交易由银联无卡快捷系统通过此交易告知交易状态
     *
     * @param upgwResultNoticeRequest 通知报文
     */
    private void dealTransResultNotice(UpgwResultNoticeRequest upgwResultNoticeRequest) throws Exception {

        rglog.debug("接受交易结果通知，根据原交易系统状态进行判断订单是否成功....");
        //获取支付订单信息 支付订单不存在则不处理该笔订单
        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
        List<PayOrderInfo> oriPayOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == oriPayOrderInfoList || oriPayOrderInfoList.isEmpty()) {
            rglog.info("支付订单不存在，当前订单未发起支付");
            return;
        }
        Optional<PayOrderInfo> esbPayOrderInfo = oriPayOrderInfoList.stream().filter(payOrderInfo -> ChannelEnum.ESB.getChannelType().equals(payOrderInfo.getMsgDstId())
                && ChannelEnum.UPGW.getChannelType().equals(payOrderInfo.getDstChannelType())).findFirst();
        if (!esbPayOrderInfo.isPresent()) {
            rglog.info("当前订单并没有发起网银网关支付，后续不处理");
            return;
        }

        //判断订单是否已经完成,若订单状态明确则不更新订单状态
        rglog.debug("判断订单是否已经完成....");
        PayOrderInfo payOrderInfo = esbPayOrderInfo.get();
        if (TransStatusEnum.TRANS_SUCC.getStatus().equals(payOrderInfo.getTransStatus()) &&
                (BizStatusEnum.FINISH.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.PART_REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.CONFIRM.getStatus().equals(payOrderInfo.getBizStatus()))) {
            rglog.info("订单已完成，不处理直接返回结果。payOrderTransStatus:<{}>,payOrderBizStatus:<{}>", payOrderInfo.getTransStatus(), payOrderInfo.getBizStatus());
            return;
        }

        //根据原订单号查询用户订单，商户订单，支付订单
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == userOrderInfo) {
            rglog.info("用户订单不存在,交易状态通知数据错误。交易终止");
            return;
        }

        //获取商户订单 若商户订单不存在，则直接更新用户订单交易状态为失败
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        List<MchntOrderInfo> mchntOrderInfos = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == mchntOrderInfos || mchntOrderInfos.isEmpty()) {
            rglog.info("商户订单不存在，instId:<{}>,sysSeqNum:<{}>", upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
            return;
        }

        /*
         * 根据原系统返回码判断原支付交易是否成功
         * 交易失败 更新用户订单/商户订单/支付订单更新为失败 并判断是否调用营销，若有营销则需要调用营销冲正
         * 交易成功 计算商户手续费-更新用户订单/商户订单/支付订单更新为成功-累计用户限额/商户限额
         * 判断是否是购买卡券交易，若是购买卡券交易需要领取卡券
         * 判断商户DO入账还是记虚拟账户
         */
        OrderService orderService = new OrderServiceImpl();
        if (!OpmsParamConstant.DUBBO_SUCCESS.equals(upgwResultNoticeRequest.getOriSysRtnCd())) {

            rglog.info("原网关支付交易失败:<{}>", upgwResultNoticeRequest.getOriSysRtnCd());
            //更新交易状态为失败
            updateOrderFail(userOrderInfo, mchntOrderInfos, esbPayOrderInfo.get(), orderService);
            //判断原交易是否使用营销，若使用营销则发起冲正
            mompComboPayRevsal(mchntOrderInfos, oriPayOrderInfoList);
        } else {

            rglog.info("原网关支付交易成功:<{}>", upgwResultNoticeRequest.getOriSysRtnCd());
            String currentDateTime = DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS");
            //更新用户订单信息
            userOrderInfo.setOrderStatus(OrderStatusEnum.FINISH.getStatus());
            userOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
            userOrderInfo.setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
            userOrderInfo.setUpdateTime(currentDateTime);
            //更新商户订单信息
            for (MchntOrderInfo mchntOrderInfo : mchntOrderInfos) {
                mchntOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
                mchntOrderInfo.setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
                mchntOrderInfo.setUpdateTime(currentDateTime);
            }
            //更新支付订单信息
            esbPayOrderInfo.get().setBizStatus(BizStatusEnum.FINISH.getStatus());
            esbPayOrderInfo.get().setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
            esbPayOrderInfo.get().setUpdateTime(currentDateTime);
            esbPayOrderInfo.get().setSettleDate(upgwResultNoticeRequest.getOriSettlmtDt().replaceAll("-", ""));
            esbPayOrderInfo.get().setRespCode(upgwResultNoticeRequest.getOriSysRtnCd());
            esbPayOrderInfo.get().setRespDesc(upgwResultNoticeRequest.getOriSysRtnDesc());

            //非购买卡券的交易的计算商户手续费并调用营销获取商户的手续费营销
            rglog.trace("流程日志-非购买卡券的交易的计算商户手续费并调用营销获取商户的手续费营销....");
            if (!"00".equals(mchntOrderInfos.get(0).getBizSceneType()) && !"02".equals(mchntOrderInfos.get(0).getBizSceneType())) {

                rglog.debug("非购买卡券的交易的计算商户手续费并调用营销获取商户的手续费营销....");
                List<PayOrderInfo> mompPayOrderList = oriPayOrderInfoList.stream().filter(item -> ShareParamConstant.MOMP_COMBO_PAY.equals(item.getDstTxnNum())).collect(Collectors.toList());
                String mompCallIndex = "0";
                if (!mompPayOrderList.isEmpty()) {
                    mompPayOrderList = mompPayOrderList.stream().sorted(Comparator.comparing(PayOrderInfo::getDstCallIndex).reversed()).collect(Collectors.toList());
                    String dstCallIndex = mompPayOrderList.get(0).getDstCallIndex();
                    mompCallIndex = String.valueOf(Integer.parseInt(dstCallIndex) + 1);
                }
                // 计算商户手续费
                String feeType = "";
                if ("02".equals(upgwResultNoticeRequest.getPyerAcctTp()) || "03".equals(upgwResultNoticeRequest.getPyerAcctTp()) || "05".equals(upgwResultNoticeRequest.getPyerAcctTp())) {
                    feeType = FeeTypeEnum.OTHER_BANK_CR_CARD.getFeeType();
                } else {
                    feeType = FeeTypeEnum.OTHER_BANK_DR_CARD.getFeeType();
                }
                MchntService mchntService = new MchntServiceImpl();
                boolean calcResult = mchntService.calcMchntFee(mchntOrderInfos, cc.rengu.igas.share.common.enums.FeeTypeEnum.OTHER_BANK_DR_CARD.getFeeType());
                if (!calcResult) {
                    rglog.info("商户手续费计算错误，交易终止");
                    return;
                }
            }

            //更新订单信息
            rglog.debug("流程日志-更新用户订单/商户订单/支付订单，计算商户手续费之后....");
            if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfos, esbPayOrderInfo.get())) {
                rglog.error("更新订单信息失败....");
            }

            //判断是否购买卡券,若是购买卡券的交易则调用营销领取卡券接口
            rglog.debug("判断是否是购买卡券交易，若是购买卡券交易则领取卡券....");
            claimCoupon(mchntOrderInfos);

            //商户入账-DO入账或记虚拟账户
            rglog.debug("商户入账判断:<{}>", mchntOrderInfos.get(0).getRealSettleFlag());
            if (AppParamConstant.YES.equals(mchntOrderInfos.get(0).getRealSettleFlag())) {
                //实时入账
                mchntRealTimeAccouting(mchntOrderInfos);
                int iReturnCode = asynnotify.transactionNotice("MchntTransNoticeService", 1, 0, 0);
                if (0 != iReturnCode) {
                    rglog.error("提交交易结果异步通知给商户失败!");
                }
            } else {
                //异步记虚拟账
                virtAcctMultiMchntAdjust(userOrderInfo, mchntOrderInfos);
            }

            //更新商户限额
            rglog.debug("更新商户限额数据....");
            MchntService mchntService = new MchntServiceImpl();
            mchntService.updateMchntTransLimit(mchntOrderInfos);

            //更新用户累计限额 判断用户是否存在，且在平台存在
            rglog.debug("更新用户限额数据.....");
            if (!StringUtil.isEmptyOrNull(userOrderInfo.getUserId())) {
                UserInfo userInfo = JSON.parseObject(RedisUtil.hashGet(upgwResultNoticeRequest.getHeader().getSession(), upgwResultNoticeRequest.getHeader().getInstId() + userOrderInfo.getUserId()), UserInfo.class);
                if (null != userInfo) {
                    rglog.info("用户:<{}>存在与平台中，需要更新其限额信息", userOrderInfo.getUserId());
                    UserService userService = new UserServiceImpl();
                    userService.updateUserTransLimit(userOrderInfo.getInstId(), userOrderInfo.getUserId(), mchntOrderInfos.get(0).getTxnNum(), userOrderInfo.getRealPayAmt());
                }
            }
        }
    }

    /**
     * 交易终态通知
     * 借记类交易在交易超时后由银联发起交易终态通知给受理侧/发卡侧交易失败
     *
     * @param upgwResultNoticeRequest 通知报文
     */
    private void dealTransFinalStateNotice(UpgwResultNoticeRequest upgwResultNoticeRequest) throws Exception {

        rglog.info("借记类交易在交易超时后由银联发起交易终态通知给受理侧/发卡侧交易失败");
        //获取支付订单信息 支付订单不存在则不处理该笔订单
        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
        List<PayOrderInfo> payOrderInfos = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriTrxId());
        if (null == payOrderInfos || payOrderInfos.isEmpty()) {
            rglog.info("支付订单不存在，当前订单未发起支付");
            return;
        }
        Optional<PayOrderInfo> esbPayOrderInfo = payOrderInfos.stream().filter(payOrderInfo -> ChannelEnum.ESB.getChannelType().equals(payOrderInfo.getMsgDstId())
                && ChannelEnum.UPGW.getChannelType().equals(payOrderInfo.getDstChannelType())).findFirst();
        if (!esbPayOrderInfo.isPresent()) {
            rglog.info("当前订单并没有发起网银网关支付，后续不处理");
            return;
        }

        //判断订单是否已经完成,若订单状态明确则不更新订单状态
        rglog.debug("判断订单是否已经完成....");
        PayOrderInfo payOrderInfo = esbPayOrderInfo.get();
        if (TransStatusEnum.TRANS_SUCC.getStatus().equals(payOrderInfo.getTransStatus()) &&
                (BizStatusEnum.FINISH.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.PART_REFUND.getStatus().equals(payOrderInfo.getBizStatus()) ||
                        BizStatusEnum.CONFIRM.getStatus().equals(payOrderInfo.getBizStatus()))) {
            rglog.info("订单已完成，不处理直接返回结果。payOrderTransStatus:<{}>,payOrderBizStatus:<{}>", payOrderInfo.getTransStatus(), payOrderInfo.getBizStatus());
            return;
        }

        //根据原订单号查询用户订单，商户订单
        rglog.debug("流程日志-获取用户订单....");
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == userOrderInfo) {
            rglog.info("用户订单不存在,交易状态通知数据错误。交易终止");
            return;
        }

        //获取商户订单 若商户订单不存在，则直接更新用户订单交易状态为失败
        rglog.debug("流程日志-获取商户订单....");
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        List<MchntOrderInfo> mchntOrderInfos = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
        if (null == mchntOrderInfos || mchntOrderInfos.isEmpty()) {
            rglog.info("商户订单不存在，instId:<{}>,sysSeqNum:<{}>", upgwResultNoticeRequest.getHeader().getInstId(), upgwResultNoticeRequest.getOriOrdrId());
            return;
        }

        //更新订单状态为失败
        rglog.info("受理侧接受到交易终态通知则更新订单失败");
        updateOrderFail(userOrderInfo, mchntOrderInfos, payOrderInfo, new OrderServiceImpl());
    }

    /**
     * 更新用户订单/商户订单/支付订单为失败
     *
     * @param userOrderInfo      用户订单
     * @param mchntOrderInfoList 商户订单
     * @param payOrderInfo       支付订单
     * @param orderService       订单服务组件
     * @throws Exception 异常
     */
    private void updateOrderFail(UserOrderInfo userOrderInfo, List<MchntOrderInfo> mchntOrderInfoList, PayOrderInfo payOrderInfo, OrderService orderService) throws Exception {

        String currentDateTime = DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS");

        //更新用户订单信息
        userOrderInfo.setOrderStatus(OrderStatusEnum.FINISH.getStatus());
        userOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
        userOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
        userOrderInfo.setUpdateTime(currentDateTime);
        //更新商户订单信息
        for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
            mchntOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mchntOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mchntOrderInfo.setUpdateTime(currentDateTime);
        }
        //更新支付订单信息
        payOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
        payOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
        payOrderInfo.setUpdateTime(currentDateTime);

        if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfoList, payOrderInfo)) {
            rglog.error("更新订单信息失败....");
        }
    }

    /**
     * 营销-合并支付冲正
     *
     * @param mchntOrderInfoList 商户订单
     * @param payOrderInfoList   支付订单列表
     */
    private void mompComboPayRevsal(List<MchntOrderInfo> mchntOrderInfoList, List<PayOrderInfo> payOrderInfoList) {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        if ("00".equals(mchntOrderInfoList.get(0).getBizSceneType())) {
            return;
        }
        DubboService dubboService = new DubboServiceImpl();
        String discountFlag = AppParamConstant.NO;
        for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
            if (mchntOrderInfo.getCustomerMarketAmt() != null && AmountUtil.compare(mchntOrderInfo.getCustomerMarketAmt(), "0.00") != 0) {
                discountFlag = AppParamConstant.YES;
                break;
            }
            if (mchntOrderInfo.getMchntDiscountFee() != null && AmountUtil.compare(mchntOrderInfo.getMchntDiscountFee(), "0.00") != 0) {
                discountFlag = AppParamConstant.YES;
                break;
            }
        }
        if (AppParamConstant.NO.equals(discountFlag)) {
            rglog.error("支付未参与任何营销，不需要冲正");
            return;
        }
        try {
            List<PayOrderInfo> payOrderInfoListMomp = payOrderInfoList.stream().filter(item -> item.getMsgDstId().equals(ChannelEnum.MOMP.getChannelType())).collect(Collectors.toList());
            /*参与营销，异步调用营销冲正接口*/
            ComboPaymentReversalRequest comboPaymentRevsalRequest = new ComboPaymentReversalRequest();
            Header header = new Header();
            header.setVersion("1.0.0");
            header.setChanlId(OpmsParamConstant.OPM_SYS_ID);
            header.setSrcSysId(AppParamConstant.SYS_ID);
            header.setBizType("00");
            header.setTxnNum("P02MO001");
            header.setTraceNo(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM) + "1");
            header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
            header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
            comboPaymentRevsalRequest.setOrigTraceNo(payOrderInfoListMomp.get(0).getChannelReconKey());
            comboPaymentRevsalRequest.setHeader(header);
            int iReturnCode = dubboService.asynCallDubboService("paymentService", OpmsParamConstant.DUBBO_METHOD_MOMP_REVERSAL, comboPaymentRevsalRequest, "AsynComboPaymentRevsalService");
            if (iReturnCode != 0) {
                rglog.error("异步营销冲正服务注册失败！");
            }
        } catch (Exception e) {
            rglog.error(e.getMessage());
            rglog.error("异步营销退款异常:<{}>", e);
        }
    }

    /**
     * 领取卡券
     *
     * @param mchntOrderInfoList 商户订单列表
     */
    private void claimCoupon(List<MchntOrderInfo> mchntOrderInfoList) {

        if (!"00".equals(mchntOrderInfoList.get(0).getBizSceneType()) && !"02".equals(mchntOrderInfoList.get(0).getBizSceneType())) {
            rglog.info("非购买卡券交易不调用营销购买接口:<{}>", mchntOrderInfoList.get(0).getBizSceneType());
            return;
        }

        DubboService dubboService = new DubboServiceImpl();
        try {

            XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
            Header header = new Header();
            header.setInstId(mchntOrderInfoList.get(0).getInstId());
            header.setVersion("1.0.0");
            header.setChanlId(OpmsParamConstant.OPM_SYS_ID);
            header.setSrcSysId(AppParamConstant.SYS_ID);
            header.setBizType(OpmsParamConstant.DUBBO_DEFAULT_BIZ_TYPE);
            header.setTxnNum("P01MO001");
            header.setTraceNo(mchntOrderInfoList.get(0).getSysSeqNum() + "0");
            header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
            header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
            ClaimCouponRequest claimCouponRequest = new ClaimCouponRequest();
            claimCouponRequest.setHeader(header);
            List<ClaimCouponMcInfoBean> mcInfoList = new ArrayList<>();
            for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
                ClaimCouponMcInfoBean claimCouponMcInfoBean = new ClaimCouponMcInfoBean();
                claimCouponMcInfoBean.setPurchaseAmt(mchntOrderInfo.getOrderAmt());
                claimCouponMcInfoBean.setClaimQuantity("1");
                String reserve = mchntOrderInfo.getTermNo();
                if (reserve != null) {
                    String[] mcInfo = reserve.split("\\|");
                    claimCouponMcInfoBean.setRuleIndex(mcInfo[1]);
                    claimCouponMcInfoBean.setMcNo(mcInfo[0]);
                }
                claimCouponMcInfoBean.setClaimUser(mchntOrderInfo.getUserId());
                claimCouponMcInfoBean.setClaimType("4");
                claimCouponMcInfoBean.setCouponLockFlag("1");
                mcInfoList.add(claimCouponMcInfoBean);
            }
            claimCouponRequest.setMcInfoList(mcInfoList);

            int iReturnCode = dubboService.asynCallDubboService(OpmsParamConstant.DUBBO_MOMP_COUPON_MANAGEMENT_SERVICE,
                    "claimCoupon", claimCouponRequest, "AsynClaimCouponService");
            if (iReturnCode != 0) {
                rglog.error("异步卡券领取服务注册失败！");
            }
        } catch (Exception e) {
            rglog.error(e.getMessage());
            rglog.error("异步卡券领取服务注册异常:<{}>", e);
        }
    }

    /**
     * 商户实时入账
     *
     * @param mchntOrderInfoList 商户订单列表
     */
    private void mchntRealTimeAccouting(List<MchntOrderInfo> mchntOrderInfoList) throws Exception {

        /*获取垫资户*/
        CsmcService csmcService = new CsmcServiceImpl();
        String roleActualAcctNo = csmcService.getRoleActualAcctNo(mchntOrderInfoList.get(0).getInstId(), SettleAcctTypeEnum.DZ_SUBJECT.getSettleAcct(), null);
        if (StringUtil.isEmptyOrNull(roleActualAcctNo)) {
            rglog.error("获取渠道户信息失败，商户实时入账失败，转t1");
            return;
        }
        ChannelCallCfg channelCallCfg = new ChannelCallCfg();
        channelCallCfg.setCallIndex("0");
        channelCallCfg.setCallChannelId(ChannelEnum.ESB.getChannelType());
        channelCallCfg.setCallChannelTxn("00010000175500");
        int callIndex = Integer.parseInt(channelCallCfg.getCallIndex());
        int iReturnCode;
        //商户收支两线的标识
        char incomeFlag = '1';

        DubboService dubboService = new DubboServiceImpl();
        for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {

            if (AppParamConstant.NO.equals(mchntOrderInfo.getRealSettleFlag())) {
                rglog.error("商户订单非实时清算");
                return;
            }

            /*查询商户结算账户信息表，判断结算周期及结算账户类型*/
            MchntInfo mchntInfo;
            try {
                MchntService mchntService = new MchntServiceImpl();
                mchntInfo = mchntService.getMchntInfo(mchntOrderInfo.getInstId(), mchntOrderInfo.getMchntNo());
                List<MchntAcctInfo> mchntAcctInfoList;
                /*获取商户结算账户信息，判断是否独立维护资料的门店,非独立维护资料的门店商户取连锁商户号进行交易*/
                if ("11".equals(mchntInfo.getMchntType()) && AppParamConstant.NO.equals(mchntInfo.getIndependentDataFlag())) {
                    mchntAcctInfoList = mchntService.getMchntAcctInfo(mchntOrderInfo.getInstId(), mchntInfo.getChainMchntNo());
                } else {
                    mchntAcctInfoList = mchntService.getMchntAcctInfo(mchntOrderInfo.getInstId(), mchntOrderInfo.getMchntNo());
                }
                Optional<MchntAcctInfo> mchntAcctInfoOpt = mchntAcctInfoList.stream().filter(item -> item.getBaseProdCode().equals(mchntOrderInfo.getBizProdCode()) && item.getFundType().equals("00")).findFirst();
                if (!mchntAcctInfoOpt.isPresent()) {
                    rglog.error("获取商户结算账户信息失败，商户实时入账失败，转t1");
                    return;
                }

                //收支两线商户实时入账金额取商户清算本金
                String mchntAmt;
                rglog.info("商户结算方式:<{}>", mchntInfo.getMchntSettleMode());
                if (incomeFlag == mchntInfo.getMchntSettleMode().charAt(1)) {
                    mchntAmt = mchntOrderInfo.getRealSettleAmt();
                } else {
                    mchntAmt = mchntOrderInfo.getMchntSettleAmt();
                }

                //登记DO支付订单，若登记失败则跳过当前商户，当前商户不再实时记账转T1
                PayOrderInfo payOrderInfo = registerD0PayOrderInfo(mchntOrderInfo, roleActualAcctNo, AcctTypeEnum.BANK_ACCT.getAcctType(),
                        mchntAcctInfoOpt.get().getSettleAcctNo(), mchntAcctInfoOpt.get().getSettleAcctType(), channelCallCfg, String.valueOf(callIndex), mchntAmt);
                if (payOrderInfo == null) {
                    rglog.info("登记支付订单失败，当前商户不再实时记账转T1");
                    continue;
                }

                //准备调用实时入账
                //TODO 由项目组实现该部分 调用D0实时清算，后调用AsynMchntD0AccoutingService根据清算结果进行处理
                iReturnCode = dubboService.asynCallDubboService("dubboService", "method", "request", "AsynMchntD0AccoutingService");
                if (iReturnCode != 0) {
                    rglog.error("异步d0入账服务注册失败！");
                }
                callIndex++;
            } catch (Exception e) {
                rglog.error(e.getMessage());
                rglog.error("商户实时入账异常:<{}>", e);
            }
        }
    }

    /**
     * 登记D0记账支付订单流水
     *
     * @param mchntOrderInfo 商户订单
     * @param payAcctNo      支付账号
     * @param payAcctType    支付账户类型
     * @param payeeAcctNo    收款账户
     * @param payeeAcctType  收款账户类型
     * @param channelCallCfg 通道服务调用配置
     * @param callIndex      调用序号
     * @return do支付订单
     */
    private PayOrderInfo registerD0PayOrderInfo(MchntOrderInfo mchntOrderInfo, String payAcctNo, String payAcctType, String payeeAcctNo,
                                                String payeeAcctType, ChannelCallCfg channelCallCfg, String callIndex, String mchntRealAmt) {

        OrderService orderService = new OrderServiceImpl();
        PayOrderInfo payOrderInfo = new PayOrderInfo();
        BeanUtil.beanCopy(mchntOrderInfo, payOrderInfo);
        payOrderInfo.setTxnNum(OpmsParamConstant.D0_ACCOUTING_TXN_NUM);
        try {
            /*系统流水号取下单交易的系统流水号*/
            payOrderInfo.setSysSeqNum(mchntOrderInfo.getSysSeqNum());
            payOrderInfo.setMsgDstId(channelCallCfg.getCallChannelId());
            if (callIndex != null) {
                payOrderInfo.setDstCallIndex(callIndex);
                payOrderInfo.setChannelSeqNum(mchntOrderInfo.getSysSeqNum() + callIndex);
                payOrderInfo.setChannelReconKey(GlobalEsbUtil.generateEsbSeqeuenceNumber(mchntOrderInfo.getInstId()));
            } else {
                payOrderInfo.setDstCallIndex(channelCallCfg.getCallIndex());
                payOrderInfo.setChannelSeqNum(mchntOrderInfo.getSysSeqNum() + channelCallCfg.getCallIndex());
                payOrderInfo.setChannelReconKey(GlobalEsbUtil.generateEsbSeqeuenceNumber(mchntOrderInfo.getInstId()));
            }
            payOrderInfo.setChannelBizType(ShareParamConstant.OTHER_SUB_SYS_ID_D0_REALTIME);
            payOrderInfo.setRealPayAmt(mchntRealAmt);
            payOrderInfo.setDstTxnNum(channelCallCfg.getCallChannelTxn());
            payOrderInfo.setPayType(PayTypeEnum.BANK_CARD.getPayType());
            payOrderInfo.setPayerAcctType(payAcctType);
            payOrderInfo.setPayerAcctInfo(payAcctNo);
            payOrderInfo.setPayeeAcctType(payeeAcctType);
            payOrderInfo.setPayeeAcctInfo(payeeAcctNo);
            payOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
            payOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
            payOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
            if (!orderService.registerOrderInfo(null, null, payOrderInfo)) {
                rglog.error("登记支付订单表失败,payOrderInfo=[{}]", JSON.toJSONString(payOrderInfo));
                return null;
            }
            return payOrderInfo;
        } catch (Exception e) {
            rglog.error(e.getMessage());
            return null;
        }
    }

    /**
     * 商户虚拟账户记账
     *
     * @param userOrderInfo      用户订单
     * @param mchntOrderInfoList 商户订单
     */
    void virtAcctMultiMchntAdjust(UserOrderInfo userOrderInfo, List<MchntOrderInfo> mchntOrderInfoList) {

        //购买卡券交易和担保支付交易不记虚拟账户
        if ("00".equals(mchntOrderInfoList.get(0).getBizSceneType()) || "02".equals(mchntOrderInfoList.get(0).getBizSceneType()) || "01".equals(mchntOrderInfoList.get(0).getBizSceneType())) {
            rglog.info("购买卡券或担保支付的交易，不记商户虚拟账");
            int iReturnCode = asynnotify.transactionNotice("MchntTransNoticeService", 1, 0, 0);
            if (0 != iReturnCode) {
                rglog.error("提交交易结果异步通知给商户失败!");
            }
            return;
        }

        //手续费特殊计费的交易不调用虚拟账户记账
        if ("0".equals(mchntOrderInfoList.get(0).getFeeInputMode())) {
            rglog.info("订单全为特殊计费，不记商户虚拟账，直接推送通知");
            int iReturnCode = asynnotify.transactionNotice("MchntTransNoticeService", 1, 0, 0);
            if (0 != iReturnCode) {
                rglog.error("提交交易结果异步通知给商户失败!");
            }
            return;
        }

        OrderService orderService = new OrderServiceImpl();
        MchntInfo mchntInfo;
        DubboService dubboService = new DubboServiceImpl();
        String realPayAmt = "0.00";
        //商户收支两线的标识
        char incomeFlag = '1';

        try {
            MchntService mchntService = new MchntServiceImpl();
            //获取虚拟账户记账时的商户数据
            List<MchtAdjustDetail> mchtAdjustDetailList = new ArrayList<>();
            for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
                if ("0".equals(mchntOrderInfo.getFeeInputMode())) {
                    continue;
                }
                MchtAdjustDetail mchtAdjustDetail = new MchtAdjustDetail();
                //00-商户
                mchtAdjustDetail.setUserType("00");
                mchntInfo = mchntService.getMchntInfo(mchntOrderInfo.getInstId(), mchntOrderInfo.getMchntNo());
                /*判断是否独立维护资料的门店*/
                if ("11".equals(mchntInfo.getMchntType()) && !AppParamConstant.YES.equals(mchntInfo.getIndependentDataFlag())) {
                    mchtAdjustDetail.setUserId(mchntInfo.getChainMchntNo());
                } else {
                    mchtAdjustDetail.setUserId(mchntInfo.getMchntNo());
                }
                /*收支两线的商户使用商户清算本金金额到虚拟账户记账，合并轧差的商户使用商户结算净额到虚拟账户记账*/
                rglog.info("当前商户:<{}>的结算模式:<{}>", mchntInfo.getMchntNo(), mchntInfo.getMchntSettleMode());
                if (incomeFlag == mchntInfo.getMchntSettleMode().charAt(1)) {
                    realPayAmt = AmountUtil.addition(realPayAmt, mchntOrderInfo.getRealSettleAmt());
                    mchtAdjustDetail.setTransAmt(mchntOrderInfo.getRealSettleAmt());
                } else {
                    realPayAmt = AmountUtil.addition(realPayAmt, mchntOrderInfo.getMchntSettleAmt());
                    mchtAdjustDetail.setTransAmt(mchntOrderInfo.getMchntSettleAmt());
                }
                //如果商户记虚拟账户的金额等于0则不记该商户的虚拟账户
                if (AmountUtil.compare("0", mchtAdjustDetail.getTransAmt()) == 0) {
                    continue;
                }
                mchtAdjustDetailList.add(mchtAdjustDetail);
            }
            if (mchtAdjustDetailList.isEmpty()) {
                rglog.error("当前订单没有需要记虚拟账户的商户交易，商户记虚拟账户的金额可能为0");
                int iReturnCode = asynnotify.transactionNotice("MchntTransNoticeService", 1, 0, 0);
                if (0 != iReturnCode) {
                    rglog.error("提交交易结果异步通知给商户失败!");
                }
                return;
            }
            List<MchtAdjustDetail> mchtAdjustDetailListFinal = new ArrayList<>();
            /*按商户分组去重，累计求和*/
            Map<String, List<MchtAdjustDetail>> groupByUserId = mchtAdjustDetailList.stream().collect(Collectors.groupingBy(MchtAdjustDetail::getUserId));
            for (Map.Entry<String, List<MchtAdjustDetail>> entryUserId : groupByUserId.entrySet()) {
                String totalTransAmt = "0";
                String userId = entryUserId.getKey();
                List<MchtAdjustDetail> entryMchtAdjustDetailList = entryUserId.getValue();
                for (MchtAdjustDetail mchtAdjustDetail : entryMchtAdjustDetailList) {
                    totalTransAmt = AmountUtil.addition(totalTransAmt, mchtAdjustDetail.getTransAmt());
                }
                MchtAdjustDetail mchtAdjustDetail = new MchtAdjustDetail();
                mchtAdjustDetail.setUserType("00");//00-商户
                mchtAdjustDetail.setUserId(userId);
                mchtAdjustDetail.setTransAmt(totalTransAmt);
                mchtAdjustDetailListFinal.add(mchtAdjustDetail);
            }

            //虚拟账户请求
            cc.rengu.igas.acct.facade.base.Header header = new cc.rengu.igas.acct.facade.base.Header();
            header.setInstId(userOrderInfo.getInstId());
            header.setChanlId(OpmsParamConstant.OPM_SYS_ID);
            header.setSrcSysId(AppParamConstant.SYS_ID);
            header.setBizType("00");
            header.setTxnNum("P01AT002");
            header.setVersion("1.0.0");
            header.setTraceNo(userOrderInfo.getSysSeqNum() + "0");
            header.setTransTime(DateUtil.getCurrentTime());
            header.setTransDate(DateUtil.getCurrentDate());
            VirtAcctMultiMchntAdjustRequest request = new VirtAcctMultiMchntAdjustRequest();
            request.setHeader(header);
            request.setAcctType("00");
            request.setDebitCreditFlag("C");
            request.setMchtAdjustDetailList(mchtAdjustDetailListFinal);

            /*记账前登记支付订单表*/
            PayOrderInfo acctPayOrderInfo = convPayOrderInfo(userOrderInfo, ChannelEnum.ACCT.getChannelType(), "P01AT002", "0");
            acctPayOrderInfo.setRealPayAmt(realPayAmt);
            acctPayOrderInfo.setTxnNum(mchntOrderInfoList.get(0).getTxnNum());
            acctPayOrderInfo.setBizType(mchntOrderInfoList.get(0).getBizType());
            if (!orderService.registerOrderInfo(null, null, acctPayOrderInfo)) {
                rglog.error("登记虚拟账户记账支付订单失败");
                return;
            }

            //异步调起虚拟账户记账服务
            int iReturnCode = dubboService.asynCallDubboService(OpmsParamConstant.DUBBO_ACCT_VIRTACCT_SERVICE,
                    OpmsParamConstant.DUBBO_ACCT_VIRTACCTMULTIMCHNTADJUST, request, OpmsServiceConstant.ASYN_VIRTACCT_MULTIMCHNT_ADJUST_SERVICE);
            if (iReturnCode != 0) {
                rglog.error("异步虚拟账户记账服务注册失败！");
            } else {
                rglog.error("异步虚拟账户记账服务注册成功！");
            }
        } catch (Exception e) {
            rglog.error("登记虚拟账户记账支付订单失败:<{}>", e);
        }
    }

    /**
     * 登记虚拟账户支付订单表
     *
     * @param userOrderInfo 用户订单
     * @param chanId        渠道ID
     * @param destTxnNum    交易码
     * @return 虚拟账户支付订单表
     * @throws Exception 异常
     */
    private PayOrderInfo convPayOrderInfo(UserOrderInfo userOrderInfo, String chanId, String destTxnNum, String payIndex) {
        PayOrderInfo payOrderInfo = new PayOrderInfo();
        BeanUtil.beanCopy(userOrderInfo, payOrderInfo);
        if (payOrderInfo.getOrderAmt() == null || payOrderInfo.getOrderAmt().isEmpty()) {
            payOrderInfo.setOrderAmt("0.00");
        }
        payOrderInfo.setTxnNum(userOrderInfo.getTxnNum());
        payOrderInfo.setDstCallIndex(payIndex);
        payOrderInfo.setMsgDstId(chanId);
        payOrderInfo.setChannelSeqNum(payOrderInfo.getSysSeqNum() + payIndex);
        payOrderInfo.setChannelReconKey(payOrderInfo.getSysSeqNum() + payIndex);
        payOrderInfo.setDstTxnNum(destTxnNum);
        payOrderInfo.setPayType(PayTypeEnum.OTHER.getPayType());
        payOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
        payOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        payOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        rglog.debug("虚拟账户记账登记支付订单表实体:<{}>", JSON.toJSONString(payOrderInfo));
        return payOrderInfo;
    }

    @Override
    public ChannelCallCfg channelCallSceneDiscern(Object request, List<ChannelCallCfg> channelCallCfgList) throws Exception {
        return null;
    }

    @Override
    public CheckResultEnum channelCallPreCheck(Object request, ChannelCallCfg channelCallCfg, OrderInfo orderInfo) throws Exception {
        return null;
    }

    @Override
    public TransStatusEnum channelCallResultProc(Object request, ChannelCallCfg channelCallCfg, TransStatusEnum transStatusEnum, Object channelResponse, OrderInfo needUpdateOrderInfo) throws Exception {
        return null;
    }
}

